package com.petadoption.serverclient.controller;


import com.petadoption.serverclient.entity.Images;
import com.petadoption.serverclient.entity.Productcategory;
import com.petadoption.serverclient.service.IImagesService;
import com.petadoption.serverclient.service.IProductcategoryService;
import com.petadoption.serverclient.utils.Result;
import com.petadoption.serverclient.vo.ProductcategoryVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ProductcategoryController {

    @Resource
    private IProductcategoryService productcategoryService;
    @Resource
    private IImagesService imagesService;

    @Resource
    private Result result;


    @GetMapping("/plan")
    public Result<ProductcategoryVO> findImage() {
        ProductcategoryVO productcategoryVO = new ProductcategoryVO();
        List<Productcategory> ProductcategoryList = productcategoryService.findImages();
        Images planbig = imagesService.findImageByName("planbig");
        Images plansmall = imagesService.findImageByName("plansmall");
        productcategoryVO.setPlanbig(planbig.getImagesUrl());
        productcategoryVO.setPlansmall(plansmall.getImagesUrl());
        productcategoryVO.setClassifyicon(ProductcategoryList);
        if (ProductcategoryList.isEmpty()) return result.fail("暂无数据");
        return result.success("宠物信息", productcategoryVO);

    }
}
